package com.example.tkmapper.controller;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

/**
 * @author huxiao
 * @description Test
 * @date 2022/4/19 10:25 上午
 */
public class Test {
    public static void main(String[] args) throws TesseractException {
        ITesseract instance = new Tesseract();
        // 引入tess4j源码包路径
        // 如果未将tessdata放在根目录下需要指定绝对路径
        instance.setDatapath("/download/Tess4J/tessdata");
        // 指定中文识别包
        instance.setLanguage("chi_sim");
        // 指定识别图片路径
        File imgDir = new File("/Desktop/test.png");
        long startTime = System.currentTimeMillis();
        String ocrResult = instance.doOCR(imgDir);
        // 输出识别结果
        System.out.println("识别结果: \n" + ocrResult + "\n 耗时：" + (System.currentTimeMillis() - startTime) + "ms");
    }
}
